package com.qq.input_monthy_unit.controller;


import com.alibaba.fastjson.JSONObject;
import com.qq.input_monthy_unit.entity.InputMonthyUnit;
import com.qq.input_monthy_unit.entity.LineInputTable;
import com.qq.input_monthy_unit.service.ILineInputTableService;
import com.qq.input_monthy_unit.service.impl.InputMonthyUnitServiceImpl;
import com.qq.input_monthy_unit.service.impl.LineInputTableServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨清林
 * @since 2021-01-19
 */
@RestController
@RequestMapping("/input_monthy_unit/line-input-table")
public class LineInputTableController {

    @Autowired
    LineInputTableServiceImpl lineInputTableService;

    @Autowired
    InputMonthyUnitServiceImpl inputMonthyUnitService;

    @RequestMapping("/index")

    public String index(Model model) {
        //查询所有的线条

        List<String> linelist = lineInputTableService.queryAllLine();
        //查询该月份
        List<String> monthyist = inputMonthyUnitService.queryByGroupMonthy();

        Map<String, Object> line_monery_map = new HashMap<>();


        List<Map<String, Object>> maplist2 = new ArrayList<>();
        List<LineInputTable> lineInputTablelist = lineInputTableService.queryAllLine_input();
        for (String line : linelist
        ) {

            //   List<Double> moneryCollect = inputMonthyUnitList.stream().map(e -> e.getMonery()).collect(Collectors.toList());
//            List<String> monthyCollect = inputMonthyUnitList.stream().map(e -> e.getMonthy()).collect(Collectors.toList());
//            List<LineInputTable> collect = lineInputTablelist.stream()
//                    .filter((e) -> e.getLine().equals(line)).collect(Collectors.toList());
            List<Double> monerylist = lineInputTableService.querySUMMoneryByLine(line);

            Map<String, Object> mapdate2 = new HashMap<>();
            mapdate2.put("name", line);
            mapdate2.put("data", monerylist);

            maplist2.add(mapdate2);


        }
        String jsonStr =  JSONObject.toJSONString(maplist2);
        model.addAttribute("d1",jsonStr);
        model.addAttribute("monthylist",JSONObject.toJSONString(monthyist));
        return "line-input";
    }

}
